<?php
namespace Application\Model;
use Zend\Session\Storage\ArrayStorage;
use Zend\Session\SessionManager;
class vn3dUtil{
    const TOTAL_DOWNLOAD=10;
//     const DOMAIN="http://vn3d.com";
    const DOMAIN="http://3dbinh.com";

    public static function convertUrlSeo($title) {
    	$url = vn3dUtil::covertUnicode ( $title );
    	$url = str_replace ( " ", "-", $url );
    	$url = preg_replace ( '/[^0-9a-zA-Z-]/', '', $url );
    	return strtolower ( urlencode ( $url ) . ".html" );
    }
    public static function covertUnicode($str) {
    	$str = strtolower ( $str );
    	$unicode = array (
    			'a' => 'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',
    			'd' => 'đ',
    			'e' => 'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
    			'i' => 'í|ì|ỉ|ĩ|ị',
    			'o' => 'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
    			'u' => 'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
    			'y' => 'ý|ỳ|ỷ|ỹ|ỵ',
    			'A' => 'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
    			'D' => 'Đ',
    			'E' => 'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
    			'I' => 'Í|Ì|Ỉ|Ĩ|Ị',
    			'O' => 'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
    			'U' => 'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
    			'Y' => 'Ý|Ỳ|Ỷ|Ỹ|Ỵ'
    	);
    	foreach ( $unicode as $nonUnicode => $uni ) {
    		$str = preg_replace ( "/($uni)/i", $nonUnicode, $str );
    	}
    	return $str;
    }

    public static function getProductFileHtml($product) {

        $productID=$product->id;
        $productName=$product->name;
        $productHtml='<a class="download_product_file"
            target="_blank"
            href="/download/'.$productID.'">'.$productName.'
        	</a>';

        return  $productHtml;
    }
    public static function getImageHtml($image) {

        $imageID=$image->id;
        $titleImage=$image->name;
        $imageHtml='<a class="fancy_grouped_elements"
            rel="faq_group_fancy"
            href="/image/'.$imageID.'/'.$imageID.'.png">
            <img style="-webkit-user-select: none"
        	alt="'.$titleImage.'" title="'.$titleImage.'"
        	src="/image/'.$imageID.'/'.$imageID.'.png">
        	</a>';

        return  $imageHtml;
    }
    public static function getBannerProductHtml($product) {

        $imageID=$product->id;
        $titleImage=$product->name;
        $imageHtml='<a class="fancy_grouped_elements"
            rel="faq_group_fancy"
            href="/banner/'.$imageID.'/'.$imageID.'.png">
            <img style="-webkit-user-select: none"
        	alt="'.$titleImage.'" title="'.$titleImage.'"
        	src="/banner/'.$imageID.'/'.$imageID.'.png">
        	</a>';

        return  $imageHtml;
    }
    public static function getBannerProductLink($product) {

        $imageID=$product->id;
        $titleImage=$product->name;
        $urlseo=vn3dUtil::convertUrlSeo($product->name);
        $imageHtml='<a
            href="/store/product/'.$imageID.'/'.$urlseo.'">
            <img style="-webkit-user-select: none"
        	alt="'.$titleImage.'" title="'.$titleImage.'"
        	src="/banner/'.$imageID.'/'.$imageID.'.png">
        	</a>';

        return  $imageHtml;
    }

    public static function setVariableSession($key,$value){
        $populateStorage = array($key => $value);
        $storage = new ArrayStorage($populateStorage);
        $manager = new SessionManager();
        $manager->setStorage($storage);
    }
    public static function getVariableSession($key){

        $manager = new SessionManager();
        $storage=$manager->getStorage();
        return $storage;
    }

    public static function checkAuth($controller){
        $authService=$controller->getServiceLocator()->get("Zend\Authentication\AuthenticationService");
        $isAuth=$authService->getStorage()
            ->getSessionManager()
            ->getSaveHandler()
            ->read($authService->getStorage()
            ->getSessionId());
        return $isAuth;

    }
//     public static function getPaypalConfig()
//     {
//         $config = array(
// //             'mode' => 'sandbox',
//             'mode' => 'live' ,
//             'acct1.UserName' => 'lesondk_api1.gmail.com',
//             'acct1.Password' => 'ZDCGWZEQGXMF9FAR',
//             'acct1.Signature' => 'Ax7ghm3nPNTi06TiPXUCDvN6amlqAkLAR2januNjLTrUYLwpp0GtHT15'
//                     );

//         return $config;

//     }
    public static function getPaypalConfig()
    {
       $config = array(
            'mode' => 'sandbox',
            // 'mode' => 'live' ,
            'acct1.UserName' => 'sang89vh-facilitator_api1.gmail.com',
            'acct1.Password' => '1391596213',
            'acct1.Signature' => 'AlwsyLtNxeGYEqIbCktDdz.NfoUyAFwWTTVovQf1xG2y-iUwv1Knsd.j'
                    );

        return $config;

    }
}